//
//  WHNFourthViewController.m
//  YiQiTingShu
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 直到世界的尽头. All rights reserved.
//  直播-排行榜-更多推出页

#import "WHNFourthViewController.h"
#import "AFTools.h"
#import "WHNLive.h"
#import "WHNTableViewCell.h"
#import <MJExtension.h>
#import <UIImageView+WebCache.h>
#import "WHNThirdViewController.h"
#import <MBProgressHUD.h>
#import "PlayerButton.h"

@interface WHNFourthViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSMutableArray *dataSource;
@property(nonatomic, strong)MBProgressHUD *progressView;

@end

@implementation WHNFourthViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view NightWithType:UIViewColorTypeNormal];
    self.title = @"电台排行榜";
    [self.view addSubview:self.tableView];
    [self getData];
    [self.view addSubview:self.progressView];
}
#pragma mark 获取数据
-(void)getData
{
    _dataSource = [NSMutableArray array];
    [AFTools getDataByURLString:_string WithDataBlock:^(id data) {
        _dataSource = [WHNLive mj_objectArrayWithKeyValuesArray:[data objectForKey:@"result"]];
        
        [_tableView reloadData];
        [_progressView removeFromSuperview];
    }];
}
-(MBProgressHUD *)progressView
{
    if (!_progressView) {
        _progressView = [[MBProgressHUD alloc]initWithView:self.view];
        _progressView.labelText = @"加载中";
        [_progressView setMode:MBProgressHUDModeIndeterminate];
        [_progressView show:YES];
        [_progressView NightWithType:UIViewColorTypeNormal];
    }
    return _progressView;
}
#pragma mark tableView初始化,懒加载
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = 0;
    }
    return _tableView;
}
//#pragma mark 视图将出现时
//-(void)viewWillAppear:(BOOL)animated
//{
//    self.tabBarController.tabBar.hidden = YES;
//}
//-(void)viewWillDisappear:(BOOL)animated
//{
//    self.tabBarController.tabBar.hidden = NO;
//    [PlayerButton shareButton].hidden = YES;
//}

#pragma mark - tableview cell样式
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    WHNTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[WHNTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.kind = WHNTableViewCellKindTwo;
    }
    cell.NumberLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row + 1];
    [cell.MainImageView sd_setImageWithURL:[NSURL URLWithString:[_dataSource[indexPath.row] radioCoverSmall]] placeholderImage:[UIImage imageNamed:@"placeholderZh"]];
    cell.TitleLabel.text = [_dataSource[indexPath.row] rname];
    cell.NameLabel.text = [NSString stringWithFormat:@"正在直播: %@", [_dataSource[indexPath.row] programName]];
    CGFloat a = [[_dataSource[indexPath.row] radioPlayCount]integerValue]/ 10000;
    cell.JiLabel.text = [NSString stringWithFormat:@"%.1f万人", a];
    cell.IconImageView.image = [UIImage imageNamed:@"sanjiao1"];
    cell.LeftImageView.image = [UIImage imageNamed:@"xiangyou"];
    
    return cell;
}
#pragma mark cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100 * FitHeight;
}
#pragma mark cell个数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}
#pragma mark 点击
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WHNThirdViewController *thirdVC = [[WHNThirdViewController alloc]init];
    thirdVC.WHNPic = [_dataSource[indexPath.row]radioCoverSmall];
    thirdVC.WHNCount = [_dataSource[indexPath.row]radioPlayCount];
    thirdVC.RadioId = [_dataSource[indexPath.row]radioId];
    thirdVC.Rname = [_dataSource[indexPath.row]rname];
    [self.navigationController pushViewController:thirdVC animated:YES];
}












- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
